//
//  MsgTable.h
//  iCan - iPhone Context-Aware Navigation
//  Carnegie Mellon University - 18-842 Distributed Systems
//
//  Created by Andrew Santell on 3/26/12.
//  Copyright (c) 2012 Andrew Santell. All rights reserved.

#import <UIKit/UIKit.h>
#import "iCanAppDelegate.h"
#import "SpinnerView.h"
#import <sqlite3.h>
#import "Message.h"

@interface MsgTable : UITableViewController <UITableViewDelegate, UITableViewDataSource, NSStreamDelegate>
{
    iCanAppDelegate *appDelegate;
    NSString *result, *message, *recipient, *messageData;
    NSInputStream *inputStream;
    NSOutputStream *outputStream;
    NSArray *totalArray;
    NSString *filePath;
    NSMutableArray *messages;
    BOOL badCookie;
    
}

@property (retain, nonatomic) iCanAppDelegate *appDelegate;
@property (retain, nonatomic) NSInputStream *inputStream;
@property (retain, nonatomic) NSOutputStream *outputStream;
@property (retain, nonatomic) SpinnerView *spinner;
@property (retain, nonatomic) NSString *result;
@property (retain, nonatomic) NSString *message;
@property (strong, nonatomic) NSArray *totalArray;
@property (strong, nonatomic) NSMutableArray *messages;
@property (retain, nonatomic) NSString *recipient;
@property (retain, nonatomic) NSString *messageData;
@property (retain, nonatomic) NSString *filePath;
@property BOOL badCookie;
@property sqlite3 *messageDB;

- (void) checkMessages;
- (void) analyzeResult;
- (void) initNetworkCommunication;
- (void) stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent;
- (void) setupDB;
- (long) addMessageToDB: (Message *) msg;
- (void) removeMessageFromDB: (Message *) msg;
- (void) copyDatabaseIfNeeded;
- (void) createArrayFromDB;
- (NSString *) getDBPath;

@end
